﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ComputerizedRehabForms
{
    public partial class BellsTestForm : Form
    {
        Random rnd = new Random();
        int correct_button;
        string img_name = "penguin";
        bool hasSelected = false;

        public BellsTestForm()
        {
            InitializeComponent();
            GenerateSelection();
        }

        private void BellsTestForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        private void GenerateSelection()
        {
            //TODO - Make this generate one of the 15 Bells Test Images along
            //       with 2 random names along with the correct name. Have them
            //       appear in random spots.

            //Clear out the button text
            left_button.Text = String.Empty;
            middle_button.Text = String.Empty;
            right_button.Text = String.Empty;
            correct_button = rnd.Next(0, 4);


            switch (correct_button) {
                case 1:
                    left_button.Text = img_name;
                    break;
                case 2:
                    middle_button.Text = img_name;
                    break;
                case 3:
                    right_button.Text = img_name;
                    break;
                default:
                    middle_button.Text = img_name;
                    break;
            }
        }

        private void left_button_Click(object sender, EventArgs e)
        {
            //the other buttons have to be set the the default color.
            makeButtonsDefaultColor();

            //Highlight the button, set selection to true
            left_button.BackColor = Color.Yellow;
            hasSelected = true;
        }

        private void middle_button_Click(object sender, EventArgs e)
        {
            //the other buttons have to be set the the default color.
            makeButtonsDefaultColor();

            //Highlight the button, set selection to true
            middle_button.BackColor = Color.Yellow;
            hasSelected = true;
            
        }

        private void right_button_Click(object sender, EventArgs e)
        {
            //the other buttons have to be set the the default color.
            makeButtonsDefaultColor();

            //Highlight the button, set selection to true
            right_button.BackColor = Color.Yellow;
            hasSelected = true;
        }

        private void BellsTestForm_KeyDown(object sender, KeyEventArgs e)
        {
            //if user has made a selection
            if (hasSelected)
            {
                //If the right key is pressed, to confirm correct selection
                //TODO - change this key to enter. Will have to make custom button
                //       that is unfocusable. So hitting Enter will not 'click' the button
                //       Hopefully this will remove the blue outline too
                if (e.KeyCode == Keys.P)
                {
                    makeButtonsDefaultColor();

                    //Generate a new selection, set hasSelected to false for the new selection
                    GenerateSelection();
                    hasSelected = false;
                }
            }
        }

        /*
         * This private method will set all the buttons to the default color.
         * */
        private void makeButtonsDefaultColor()
        {
            left_button.BackColor = SystemColors.Control;
            left_button.UseVisualStyleBackColor = true;
            middle_button.BackColor = SystemColors.Control;
            middle_button.UseVisualStyleBackColor = true;
            right_button.BackColor = SystemColors.Control;
            right_button.UseVisualStyleBackColor = true;
        }

    }
}
